data(anscombe)
anscombe[ , c(1,5,2,6,3,7,4,8)]
## x1 y1 x2 y2 x3 y3 x4 y4
## 1 10 8.04 10 9.14 10 7.46 8 6.58
## 2 8 6.95 8 8.14 8 6.77 8 5.76
## 3 13 7.58 13 8.74 13 12.74 8 7.71
## 4 9 8.81 9 8.77 9 7.11 8 8.84
## 5 11 8.33 11 9.26 11 7.81 8 8.47
## 6 14 9.96 14 8.10 14 8.84 8 7.04
## 7 6 7.24 6 6.13 6 6.08 8 5.25
## 8 4 4.26 4 3.10 4 5.39 19 12.50
## 9 12 10.84 12 9.13 12 8.15 8 5.56
## 10 7 4.82 7 7.26 7 6.42 8 7.91
## 11 5 5.68 5 4.74 5 5.73 8 6.89
…exploratory…
…analysis and diagnosis…
…presentation…
“…the relational graphic - in its barest form, the scatterplot and its variants - is the greatest of all graphical designs. It links at least two variables, encouraging and even imploring the viewer to assess the possible causal relationship between the plotted variables.”
Edward Tufte
Adapted from Tufte
But everything can be seen as a combination of mappings, layers, stats, geoms, scales, coordinates, facets
# Preparing the input data...
graphData <- toPlotData %>%
ungroup() %>%
select(Data1, Data2, Area, Year) %>%
gather(variable, Value, -Year, -Area) %>%
mutate(variable = ifelse(variable == "Data1", "Annual GDP growth rates", "Annual percentage changes of new dwelling approvals"))
# Preparing labels...
labs <- data.frame(
Year = c(2009, 2006),
Area = c("West Coast", "West Coast"),
variable = c("Annual percentage changes of new dwelling approvals", "Annual GDP growth rates"),
Value = c(-34, 24)
)
# specify default data and mappings to aesthetics:
ggplot(data = graphData, aes(x = Year, y = Value / 100, colour = variable)) +
# Layer 1 uses default data and mappings, and line geom:
geom_line() +
# Layer 2 uses its own data, adds an aesthetic, and text geom:
geom_text(data = labs, aes(label = variable), family = "Calibri",
hjust = 0.5, size = 3) +
# Facets for overall plot
facet_wrap(~Area) +
# scale for the y and colour aesthetics
scale_y_continuous("Growth per year", label = percent) +
scale_colour_manual(values = mbie::mbie.cols(c(1, 3))) +
# titles and guides
labs(x = "") +
ggtitle("Economic growth and change of new dwelling approvals, selected NZ regions\n") +
# theme for look and feel
theme_solarized(base_family = "Calibri") +
theme(panel.background = element_blank()) +
theme(legend.position = "none",
strip.background = element_rect(colour = NA, fill = stripcolour))
mbiemaps package